<?php
/**
 * Created by PhpStorm.
 * User: chen
 * Date: 2015/7/21
 * Time: 9:57
 */
class LoginAction extends Action{
    public function _initialize(){
        $this->loadConfig();
    }
    public function login(){
        $this->loadConfig();
        $data = M('admin')->select();
        if(IS_POST){
            $name = I('post.username');
            $pwd = I('post.password');
            
            //其他用户的判定
            $adminModel=D('AdminUser');
            $map=array();
            $map['name']=$name;
            $map['password']=$pwd;
            $visit=$adminModel->where($map)->find();
            if($visit['status'] == 2 || $visit['is_delete'] == 1){
                $this->error('此账号已作废,无法进入后台!');
            }
            $id=$adminModel->where($map)->getField('id');
            if ($id) {
                //记录这次登陆时间
                $adminModel->addLoginTime($id);
                //把用户id写入缓存
                setLoginUid($id);
                $login['login_end_time'] = time() + 600;//后台登录失效时间5分钟
                M('use_time')->where(array('id'=>1))->save($login);
                $this->success('登陆成功', U('/Admin'));
            } else{
                    $this->error('登陆失败！');
            }
            exit;
        }
        $this->display();
    }
    public function verify(){
        ob_clean();
        import('ORG.Util.Image');
        Image::buildImageVerify();
//        Image::GBVerify();
    }

    public function loadConfig(){
        $tmplParseString = array();
        $tmplParseString['__STATIC__'] = __APP__ . '/static';
        $tmplParseString['__UPLOAD__'] = __APP__ . '/upload';
        $tmplParseString['__PUBLIC__'] = __APP__ . '/public';
        $tmplParseString['__SITE_URL__'] = __APP__;
        C('TMPL_PARSE_STRING', $tmplParseString);
        $this->assign('baseurl',getBaseUrl());
        $this->assign('app',__APP__);
    }

    public function miss(){
        $this->display();
    }
}

